package com.gxa.controller;

import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.param.ServeParam;
import com.gxa.param.TableParam;
import com.gxa.pojo.Empl;
import com.gxa.pojo.Serve;
import com.gxa.service.ServeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/serve")
public class ServeController {
    @Autowired
    private ServeService service;


    /**
     * 服务列表页面
     * @return
     */
    @GetMapping("/list/page")
    public String list(){
        return "serve/serve-list";
    }

    /**
     * 服务数据
     * @return
     */
    @PostMapping("/list/data")
    @ResponseBody
//    public LayR listData(TableParam param){
//        return service.list(param);
//    }

    public LayR listData(ServeParam param){
        System.out.println(param.toString());
        return service.list(param);

    }


    /**
     * 服务的添加页面
     * @return
     */
    @GetMapping("/add/page")
    public String addPage(){
        return "serve/serve-add";
    }

    /**
     * 添加服务
     * @param serve
     * @return
     */
    @PostMapping("/add/do")
    @ResponseBody
    public R add(Serve serve){
        return service.add(serve);
    }

    /**
     * 删除一条服务
     * @return
     */
    @PostMapping("/delone")
    @ResponseBody
    public R delete(Integer serveId){
        return service.delone(serveId);
    }

    /**
     * 删除多个服务
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public R delete(@RequestParam("ids[]") String[] ids){
        return service.deleteAll(ids);
    }

    /**
     * 服务的编辑页面
     * @return
     */
    @GetMapping("/edit/page")
    public String editPage(Integer id, Model model){
        model.addAttribute("serveEditId", id);
        return "serve/serve-edit";
    }

    @PostMapping("/edit/do")
    @ResponseBody
    public R edit(Serve serve)
    {
        return service.edit(serve);
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @PostMapping("/detail")
    @ResponseBody
    public R detail(Integer id){
        return service.detail(id);
    }

    /**
     * 服务分配页面
     * @return
     */
    @GetMapping("/allocate/page")
    public String allocate(){
        return "serve/serve-allocate";
    }


    /**
     * 服务处理页面
     * @return
     */
    @GetMapping("/conduct/page")
    public String conduct(){
        return "serve/serve-conduct";
    }

    /**
     * 服务反馈页面
     * @return
     */
    @GetMapping("/feedback/page")
    public String feedback(){
        return "serve/serve-feedback";
    }

    /**
     * 服务的查看页面
     * @return
     */
    @GetMapping("/view/page")
    public String viewPage(Integer id, Model model){
        model.addAttribute("serveEditId", id);
        return "serve/serve-view";
    }

    @PostMapping("/view/do")
    @ResponseBody
    public R view(Serve serve)
    {
        return service.view(serve);
    }



    /**
     * 提交多个服务
     * @return
     */
    @PostMapping("/submit")
    @ResponseBody
    public R submit(@RequestParam("ids[]") String[] ids){
        return service.submitAll(ids);
    }



    /**
     * 服务的分配处理人页面
     * @return
     */
    @GetMapping("/allocate/pending/page")
    public String allocatePendingPage(Integer id, Model model){
        model.addAttribute("serveEditId", id);
        return "serve/serve-allocate-pending";
    }

    /**
     * 服务
     * @param serve
     * @return
     */
    @PostMapping("/allocate/pending/do")
    @ResponseBody
    public R allocatePending(Serve serve){
        return service.allocatePending(serve);
    }


    @GetMapping("/conductStatus/page")
    public String conductStatusPage(Integer id, Model model){
        model.addAttribute("serveEditId", id);
        return "serve/serve-conductStatus";
    }

    @PostMapping("/conductStatus/do")
    @ResponseBody
    public R conductStatus(Serve serve){
        return service.conductStatus(serve);
    }
}


